﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Collections.Generic;

namespace CalculatorLogic
{
    /// <summary>
    /// A singleton object used to generate many different graphs
    /// </summary>
    public class GraphGenerator
    {
        #region fields
        /// <summary>
        /// the only instance of this object available
        /// </summary>
        private static GraphGenerator instance;

        #endregion fields

        #region Constructors

        private GraphGenerator()
        { 
        
        }

        #endregion Constructors

        #region PublicMethods
        /// <summary>
        /// The only method for getting the GraphGenerator
        /// </summary>
        /// <returns></returns>
        public static GraphGenerator GetGraphGenerator()
        { 
            if (instance == null)
            {
                instance = new GraphGenerator();
            }
            return instance;
        }

        /// <summary>
        /// Create a graph object from specified parameters
        /// </summary>
        /// <param name="xWidth"> the width of the x axis of the graph</param>
        /// <param name="xHeight">the height of the x axis of the graph</param>
        /// <param name="yWidth">the width of the y axis of the graph</param>
        /// <param name="yHeight">the height of the y axis of the graph</param>
        /// <param name="centerPoint">the center or origin as a Point on the graph</param>
        /// <returns>A Graph object</returns>
        //public Graph GenerateGraph(double xWidth,
        //                            double xHeight,
        //                            double yWidth,
        //                            double yHeight,
        //                            Point centerPoint
        //                            )
        //{
        //    Graph newGraph = new Graph(xWidth, xHeight, yWidth, yHeight, centerPoint);
        //    return newGraph;
        //}

        public Graph GenerateGraph(double xMin, double xMax, double xScale, double yMin, double yMax, double yScale)
        {
            Axis tempXAxis;
            Axis tempYAxis;
            Graph tempGraph;
            //double xMin = xMin;
            //double xMax = xMax;
            //double xScale = xScale;
            //double yMin = yMin;
            //double yMax = yMax;
            //double yScale = yScale;

            Color AxisColor = new Color();
            double zeroValue = 0.0d;
            //AxisColor.A = 1;
            //AxisColor.R = 0;
            //AxisColor.G = 0;
            //AxisColor.B = 0;
            //create x axis
            tempXAxis = createAxis(xMin, xMax, xScale, AxisColor);

            //create y axis
            tempYAxis = createAxis(yMin, yMax, yScale, AxisColor);
            //THERE IS SOME MAJOR ISSUE THAT WILL NOT ALLOW ME TO ADJUST A POINT OBJECT!!!!
            ///ARGGGGHHHH!!!!!!
            
            //setup x axis
            Point xAxisStartPoint; 
            xAxisStartPoint = createPoint(tempXAxis.Min, zeroValue);
            Point xAxisEndPoint; 
            xAxisEndPoint = createPoint(tempXAxis.Max, zeroValue);

            tempXAxis.SetName("X");
            tempXAxis.SetStartPoint(xAxisStartPoint);
            tempXAxis.SetEndPoint(xAxisEndPoint);

            //set up y axis
            Point yAxisStartPoint; 
            yAxisStartPoint = createPoint(zeroValue, tempYAxis.Min);
            Point yAxisEndPoint;
            yAxisEndPoint = createPoint(zeroValue, tempYAxis.Max);

            tempYAxis.SetName("Y");
            tempYAxis.SetStartPoint(yAxisStartPoint);
            tempYAxis.SetEndPoint(yAxisEndPoint);

            tempGraph = createGraph(tempXAxis, tempYAxis);
            

            return tempGraph;
        }
        /// <summary>
        /// create an axis object 
        /// </summary>
        /// <param name="min">the min value for the axis</param>
        /// <param name="max">the max value for the axis</param>
        /// <param name="scale">the scale to use for the GraphIntervals on the axis</param>
        /// <param name="color">the color of the axis</param>
        /// <returns></returns>
        private Axis createAxis(double min, double max, double scale, Color color)
        {
            Axis tempAxis;
            tempAxis = new Axis(min, max, scale, color);
            
            return tempAxis;
        }
        /// <summary>
        /// Create the Graph object
        /// </summary>
        /// <param name="xAxis">xAxis of the graph</param>
        /// <param name="yAxis">yAxis of the graph</param>
        /// <returns>a new graph</returns>
        private Graph createGraph(Axis xAxis, Axis yAxis)
        {
            Graph tempGraph;
            tempGraph = new Graph(xAxis, yAxis);
            return tempGraph;
        }

        private Point createPoint(double x, double y)
        {
            Point tempPoint; 
            tempPoint = new Point(x, y);
            
            return tempPoint;
            
        }

        


        #endregion PublicMethods

        #region privateMethods
        
        /// <summary>
        /// build a single GraphInterval Marker to be drawn
        /// </summary>
        /// <param name="intervalWidth">the width of the interval marker</param>
        /// <param name="intervalHeight">the height of the interval marker</param>
        /// <param name="intervalPoint">the point on the screen or axis for the interval</param>
        /// <param name="color">the color of the interval marker</param>
        /// <returns>An instance of a GraphInterval</returns>
        private GraphInterval buildInterval(double intervalWidth, double intervalHeight, Point intervalPoint, Color color)
        {
            GraphInterval tempGraphInterval = new GraphInterval(intervalWidth, intervalHeight, intervalPoint, color);
            return tempGraphInterval;
        }

        private List<GraphInterval> buildGraphIntervalList(GraphInterval newGraphIntervalToAdd)
        {
            List<GraphInterval> tempGraphIntervals = new List<GraphInterval>();
            return tempGraphIntervals;
        }
        #endregion privateMethods
    }
}
